
package com.wake.widget.skin.handler;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.View;

import com.wake.widget.skin.NMUISkinManager;
import com.wake.widget.util.NMUIResHelper;
import com.wake.widget.util.NMUIViewHelper;
import com.wake.widget.widget.NMUIProgressBar;
import com.wake.widget.widget.NMUISlider;
import com.wake.widget.widget.roundwidget.NMUIRoundButton;

import org.jetbrains.annotations.NotNull;

public class NMUISkinRuleBackgroundHandler implements INMUISkinRuleHandler {

    @Override
    public void handle(@NotNull NMUISkinManager skinManager, @NotNull View view, @NotNull Resources.Theme theme, @NotNull String name, int attr) {
        if(view instanceof NMUIRoundButton){
            ((NMUIRoundButton)view).setBgData(
                    NMUIResHelper.getAttrColorStateList(view.getContext(), theme, attr));
        }else if(view instanceof NMUIProgressBar){
            view.setBackgroundColor(NMUIResHelper.getAttrColor(theme, attr));
        }else if(view instanceof NMUISlider){
            ((NMUISlider)view).setBarNormalColor(NMUIResHelper.getAttrColor(theme, attr));
        }else{
            NMUIViewHelper.setBackgroundKeepingPadding(view,
                    NMUIResHelper.getAttrDrawable(view.getContext(), theme, attr));
        }
    }
}
